//
//  SearchEquipment2TableViewCell.m
//  RTUApp
//
//  Created by 陈德军 on 2017/6/22.
//  Copyright © 2017年 陈德军. All rights reserved.
//

#import "SearchEquipment2TableViewCell.h"

@interface SearchEquipment2TableViewCell(){
    
}
/**
 *  序号
 */
@property (nonatomic,strong) UILabel *orderNumberLabel;
/**
 *  设备名称
 */
@property (nonatomic,strong) UILabel *equipmentNameLabel;
/**
 *  MAC地址
 */
@property (nonatomic,strong) UILabel *macIDLabel;
/**
 *  连接按钮
 */
@property (nonatomic,strong) UIButton *connectBut;
@end

@implementation SearchEquipment2TableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+(instancetype)cellWithtableView:(UITableView *)tableview
{
    static NSString *ID = @"cell2";
    SearchEquipment2TableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if(!cell)
    {
        cell = [[SearchEquipment2TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
    
}

//重写布局
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.orderNumberLabel = [UILabel new];
        self.orderNumberLabel.textAlignment = NSTextAlignmentCenter;
        self.orderNumberLabel.text = @"1";
        self.orderNumberLabel.size = CGSizeMake(50, 23);
        self.orderNumberLabel.left = 20;
        self.orderNumberLabel.top = 5;
        [self.contentView addSubview:self.orderNumberLabel];
        
        self.equipmentNameLabel = [UILabel new];
        self.equipmentNameLabel.textAlignment = NSTextAlignmentCenter;
        self.equipmentNameLabel.text = @"蓝牙设备";
        self.equipmentNameLabel.font = [UIFont systemFontOfSize:11];
        self.equipmentNameLabel.size = CGSizeMake(80, 23);
        self.equipmentNameLabel.left = self.orderNumberLabel.right+5;
        self.equipmentNameLabel.top = self.orderNumberLabel.top;
        [self.contentView addSubview:self.equipmentNameLabel];
        
        self.macIDLabel = [UILabel new];
        self.macIDLabel.textAlignment = NSTextAlignmentCenter;
        self.macIDLabel.text = @"sdfasfasdfasfasdf";
        self.macIDLabel.textAlignment = NSTextAlignmentCenter;
        self.macIDLabel.font = [UIFont systemFontOfSize:11];
        self.macIDLabel.size = CGSizeMake(130, 23);
        self.macIDLabel.left = self.equipmentNameLabel.right + 5;
        self.macIDLabel.top = self.orderNumberLabel.top;
        [self.contentView addSubview:self.macIDLabel];
        
        self.connectBut = [UIButton new];
        self.connectBut.titleLabel.font = [UIFont systemFontOfSize:11];
        self.connectBut.size = CGSizeMake(80, 35);
        self.connectBut.top = self.orderNumberLabel.top;
        self.connectBut.left = self.macIDLabel.right + 5;
        [self.connectBut setTitle:@"连接" forState:(UIControlStateNormal)];
        [self.connectBut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.connectBut addTarget:self action:@selector(btnClick:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:self.connectBut];
    }
    return self;
}

//给cell控件赋值
-(void)setModel:(SearchEquipmentModel *)model{
    self.orderNumberLabel.text = model.num;
    self.equipmentNameLabel.text = model.name;
    self.macIDLabel.text = model.macID;
    [self.connectBut setTitle:model.butTitle forState:(UIControlStateNormal)];
}



#pragma mark - 按钮点击事件，通过代理模式响应
-(void)btnClick:(UIButton *)btn
{
    //    [self.delegate didClickButton:btn];
}

@end
